package cn.glutnn.controller;


import cn.glutnn.entity.FoodRecommendations;
import cn.glutnn.entity.Result;
import cn.glutnn.service.FoodRecommendationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * (FoodRecommendations)表控制层
 *
 * @author msh
 * @since 2024-12-14 16:57:47
 */
@RestController
@RequestMapping("/foodRecommendations")
public class FoodRecommendationsController {
    /**
     * 服务对象
     */
    @Autowired
    private FoodRecommendationsService foodRecommendationsService;

    // 添加美食推荐
    @PostMapping
    public Result<String> save(@RequestBody FoodRecommendations foodRecommendations) {
        foodRecommendationsService.save(foodRecommendations);
        return Result.success("添加成功");
    }

    // 删除美食推荐
    @DeleteMapping("/{id}")
    public Result<String> delete(@PathVariable("id") Integer id) {
        foodRecommendationsService.removeById(id);
        return Result.success("删除成功");
    }

    // 修改美食推荐
    @PutMapping
    public Result<String> update(@RequestBody FoodRecommendations foodRecommendations) {
        foodRecommendationsService.updateById(foodRecommendations);
        return Result.success("修改成功");
    }

    // 根据id查询美食推荐
    @GetMapping("/{id}")
    public Result<FoodRecommendations> getById(@PathVariable("id") Integer id) {
        return Result.success(foodRecommendationsService.getById(id));
    }

    // 查询所有美食推荐
    @GetMapping("/list")
    public Result<List<FoodRecommendations>> list() {
        return Result.success(foodRecommendationsService.list());
    }
}

